﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;

namespace Microhard.Framework.MVCHelper
{
    public class ScriptGridFlowApproveButton : BaseButton
    {
        public ScriptGridFlowApproveButton()
        {
            this._assetKey = SysConst.OPERATION_APPROVE;
        }

        public override System.Web.Mvc.MvcHtmlString WriteHtml(System.Web.Mvc.HtmlHelper helper, string linkText, string actionName, string controllerName)
        {
            return base.CreateButton(SysConst.OPERATION_APPROVE, helper, this.ID, linkText, true, controllerName, actionName, SysConst.OPERATION_APPROVEFORMID);
        }

        public override string WriteJQueryReadyInnerScript(HttpContextBase helper)
        {
            StringBuilder script = new StringBuilder();
            script.Append("$('#" + this._id + "').click(function () {");
            script.Append("var cks = $('." + SysConst.GRID_CKS_CSS + ":checked');");
            script.Append("var form = $('#" + SysConst.OPERATION_APPROVEFORMID + "');");
            script.Append("if (cks.length == 0) {");
            script.Append("alert(\"请选择需要审批的数据.\");");
            script.Append("return false;");
            script.Append("}");
            script.Append("if (cks.length > 1) {");
            script.Append("alert(\"请选择一条数据以进行审批.\");");
            script.Append("return false;");
            script.Append("}");
            script.Append("form.append(\"<input type='hidden' value='\" + cks[0].value + \"' name='identity'>\");");
            script.Append("return true;");
            script.Append("});");
            return script.ToString();
        }
    }
}
